package com.jzr.bedside.controller.api;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.jzr.bedside.db1.mapper.VBedMapper;
import com.jzr.bedside.db1.model.TDept;
import com.jzr.bedside.db1.model.VBed;
import com.jzr.bedside.db1.service.TDeptService;
import com.jzr.common.entity.vo.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@Api(tags = "科室接口")
@RestController
@RequestMapping("/api/dept")
public class DeptController {
    @Autowired
    private TDeptService deptService;

    @Autowired
    private VBedMapper vBedMapper;

    @ApiOperation("获取科室列表")
    @GetMapping("/codeList")
    public Result<List<Map<String,Object>>> codeList(){
        QueryWrapper<TDept> qw = new QueryWrapper<>();
        qw.select("code,name");
        qw.orderByAsc("name");
        List<Map<String,Object>> list = deptService.listMaps(qw);
        return Result.success("成功",list);
    }

    @ApiOperation("根据科室编号，获取房间列表")
    @GetMapping("/roomList")
    public Result<List<Map<String,Object>>> roomList(@ApiParam("科室编码") String deptCode){
        QueryWrapper<VBed> qw = new QueryWrapper<>();
        qw.select("distinct room_code as code,room_code as name");
        qw.orderByAsc("room_code");
        qw.eq(VBed.DeptCode_,deptCode);
        List<Map<String,Object>> list = vBedMapper.selectMaps(qw);
        return Result.success("成功",list);
    }

    @ApiOperation("根据科室编号和房间号，获取床位列表")
    @GetMapping("/bedList")
    public Result<List<Map<String,Object>>> bedList(String deptCode,String roomCode){
        QueryWrapper<VBed> qw = new QueryWrapper<>();
        qw.select("id,bed_code as code,bed_name as name");
        qw.orderByAsc("bed_code");
        qw.eq(VBed.DeptCode_,deptCode);
        qw.eq(VBed.RoomCode_,roomCode);
        List<Map<String,Object>> list = vBedMapper.selectMaps(qw);
        return Result.success("成功",list);
    }
}
